/*! vue-events | MIT License | https://github.com/cklmercer/vue-events */

/**
 * bus plugin
 * @param Vue
 */
function plugin(Vue) {
    /* included in Vue.use  */
    // if (plugin.installed) return
    // plugin.installed = true

    const events = new Vue({
        methods: {
            emit(event, ...args) {
                this.$emit(event, ...args)
            },

            fire(event, ...args) {
                this.emit(event, ...args)
            },

            on(event, callback) {
                this.$on(event, callback)
            },

            listen(event, callback) {
                this.on(event, callback)
            },

            once(event, callback) {
                this.$once(event, callback)
            },

            off(event, callback) {
                this.$off(event, callback)
            },

            remove(event, callback) {
                this.off(event, callback)
            }
        }
    })

    Object.defineProperty(Vue.prototype, '$bus', {
        get() {
            return events
        }
    })
}

export default plugin
